<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:em="http://xmlns.jcp.org/jsf/composite/ezcomp"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputLabel value="#{messages.Knowledge}#{messages.Learning}#{messages.Status}"/>
        </ui:define>
        <ui:define name="body">
            <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
            <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
            <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:form styleClass="jsfcrud_list_form" prependId="false" enctype="multipart/form-data">
                <h:panelGrid columns="5">
                    <h:panelGrid columns="4" >
                        <h:outputLabel value="#{messages.Major}"/>
                        <h:selectOneMenu value="#{majorController.selected}" immediate="true" required="true">
                            <f:selectItem  itemLabel="#{messages.Please}#{messages.Select}"/> 
                            <f:selectItems value="#{majorControllerA.allList}"/>
                            <f:ajax render="MajorSubjectCon"/>
                        </h:selectOneMenu>
                        <h:outputLabel value="#{messages.Subject}"/>
                        <h:selectOneMenu value="#{subjectController.selected}" id="MajorSubjectCon" immediate="true" required="true">
                            <f:selectItem  itemLabel="#{messages.Please}#{messages.Select}" itemValue="null"/> 
                            <f:selectItems value="#{subjectController.selectedSubjects4Major}"/>
                            <f:ajax render="school" />
                            <!--上面的knowledgeTbl knowledge mysubjectList都是在Knowledge的List页面中的-->
                        </h:selectOneMenu>
                    </h:panelGrid>
                    <h:outputLabel value="#{messages.Class}"/>
                    <h:selectOneMenu value="#{schoolController.selected}" id="school">
                        <f:selectItem  itemLabel="#{messages.Please}#{messages.Select}"/> 
                        <f:selectItems value="#{schoolController.getAllClasses()}"/>
                        <f:ajax render="myGraph allStudent" listener="#{studentController.delSelectedStu()}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="#{messages.Student}"/>
                    <h:selectManyListbox value="#{studentController.selectedSchoolStudents}" id="allStudent">
                        <f:selectItem  itemLabel="#{messages.Please}#{messages.Select}"/>
                        <f:selectItems value="#{studentControllerA.getStudentList(schoolController.selected)}"/>
                        <f:ajax render="myGraph"/>
                    </h:selectManyListbox>
                </h:panelGrid>
                <h:inputHidden id="inputGraph" value="#{knowledgeController.getAllStudentKnowledge()}" />

                <h:panelGroup id="myGraph">

                    <svg width="960" height="600"> <g/></svg>
                    <script>
                        var svg = d3.select("svg"),
                                inner = d3.select("svg g"),
                                zoom = d3.zoom().on("zoom", function () {
                            inner.attr("transform", d3.event.transform);
                        });
                        svg.call(zoom);

                        // Create and configure the renderer
                        var render = dagreD3.render();

                        var g;

                        var inputGraph = document.querySelector("#inputGraph");
                        try {
                            g = graphlibDot.read(inputGraph.value);
                        } catch (e) {
                            inputGraph.setAttribute("class", "error");
                            throw e;
                        }

                        g.graph().transition = function (selection) {
                            return selection.transition().duration(500);
                        };

                        // Render the graph into svg g
                        d3.select("svg g").call(render, g);
                    </script>
                </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
